package com.jinlei.crm.settings.controller;


import com.jinlei.crm.commons.utils.Result;
import com.jinlei.crm.settings.entity.DicValue;
import com.jinlei.crm.settings.service.DicValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表(dicValue)表控制层
 *
 * @author makejava
 * @since 2022-06-27 15:43:53
 */
@RestController
@RequestMapping("dicValue")
public class DicValueController {
    /**
     * 服务对象
     */
    @Autowired
    private DicValueService dicValueService;

    /**
     * 分页查询
     *
     * @param pageNumber 当前页码
     * @param pageSize   每页条数
     * @param dicValue       筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    public Result listPage(@RequestParam(value = "pageNumber",defaultValue = "1") Integer pageNumber,
                           @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                           DicValue dicValue) {
        return Result.success(dicValueService.listPage(pageNumber, pageSize, dicValue));
    }

    /**
     * 查询全部
     *
     * @return 查询结果
     */
    @GetMapping("/list")
    public Result list(String typeCode) {
        DicValue dicValue = new DicValue();
        dicValue.setTypeCode(typeCode);
        return Result.success(dicValueService.list(dicValue));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/find/{id}")
    public Result findById(@PathVariable("id") String id) {
        return Result.success(dicValueService.findById(id));
    }

    /**
     * 新增数据
     *
     * @param dicValue 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public Result save(@RequestBody DicValue dicValue) {
        return Result.success(dicValueService.insert(dicValue));
    }

    /**
     * 编辑数据
     *
     * @param dicValue 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody DicValue dicValue) {
        return Result.success(dicValueService.update(dicValue));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") String id) {
        return Result.success(dicValueService.remove(id));
    }

    /**
     * 批量删除数据
     *
     * @param ids 主键数组
     * @return 删除是否成功
     */
    @DeleteMapping("/delete")
    public Result deleteBatch(String[] ids) {
        return Result.success(dicValueService.removeBatch(ids));
    }
}

